<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
//回收站
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	//搜索
	$params=array();
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$fields=array('id','title','reason','createtime');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$list=pdo_getslice('core_account_recycle',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'站点列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			'0'=>array('name'=>'title','title'=>'站点名称','type'=>'string'),
			'1'=>array('name'=>'reason','title'=>'删除原因','type'=>'string'),
			'2'=>array('name'=>'createtime','title'=>'删除日期','type'=>'time'),
		),'action'=>array(
			'0'=>array('op'=>'back','title'=>'恢复','type'=>'post'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='back'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('没有选择公众号！','error');
	}else{
		$filename=pdo_getcolumn('core_account_recycle',array('id'=>$id),'file');
		$data=cfc('files')->source_read($filename);
		if(!$data){
			exi('恢复失败！找不到公众号数据！','error');
		}
		$data=unserialize($data);
		foreach($data as $key=>$value){
			if(!empty($value)){
				if($value['0']){
					foreach($value as $v){
						pdo_insert($key,$v);
					}
				}else{
					pdo_insert($key,$value);
				}
			}
		}
		cfc('files')->source_del($filename);
		pdo_delete('core_account_recycle',array('id'=>$id));
		exi('恢复成功！');
	}
}
if($_RQ['op'] == 'del'){
	if($_RQ['del']){
		$dels=str_array($_RQ['del']);
	}else{
		$dels=array();
	}
	$id=intval($_RQ['id']);
	if($id){
		$dels[]=$id;
	}
	if(empty($dels)){
		exi('请先选择要删除的项目！','error');
	}
	foreach($dels as $id){
		$id=intval($id);
		if($id){
			$file=pdo_getcolumn('core_account_recycle',array('id'=>$id),'file');
			if($file){
				cfc('files')->source_del($file);
			}
			pdo_delete('core_account_recycle',array('id'=>$id));
		}
	}
	exi('删除成功！');
}
?>